package com.my.jwt.shiro.test1;

import com.louislivi.fastdep.shirojwt.shiro.FastDepShiroJwtAuthorization;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Set;

/**
 * 用户权限配置
 * @author timo 2021/3/19
 */
@Component
public class FastDepShiroJwtConfig extends FastDepShiroJwtAuthorization {

//    @Autowired
//    private UserRequestDataMapper userRequestDataMapper;

    @Override
    public SimpleAuthorizationInfo getAuthorizationInfo(String userId) {
        // 查询该用户下的所有权限（当前为示例仅查询用户ID真实环境替换为用户的权限值）
//        Set<String> collect = userRequestDataMapper.selectOptions().stream().map(u -> u.getUserId().toString()).collect(Collectors.toSet());
        Set<String> collect = new HashSet<>();
        collect.add("1");
        SimpleAuthorizationInfo simpleAuthorizationInfo = new SimpleAuthorizationInfo();
        System.out.println(collect);
        // 当前值为 [1]
        // 添加用户权限到SimpleAuthorizationInfo中
        simpleAuthorizationInfo.addStringPermissions(collect);
        return simpleAuthorizationInfo;
    }
}
